package com.guoxin.part1.chapter3;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/8/27
 */
public class FigthQueryTask extends Thread implements FightQuery {

    private final String origin;
    private final String destination;
    private final List<String> figthList = new ArrayList<>();

    public FigthQueryTask(String airline, String origin, String destination){
        super("["+airline+"]");
        this.origin = origin;
        this.destination = destination;
    }

    @Override
    public void run() {
        try {
            System.out.printf("%s-query from %s to %s \n",getName(),origin,destination);
            int randomVal = ThreadLocalRandom.current().nextInt(10);
            TimeUnit.SECONDS.sleep(randomVal);
            this.figthList.add(getName()+"-"+randomVal);
            System.out.printf("The Figth:%s list query successful\n",getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<String> get() {
        return this.figthList;
    }
}
